home *** CD-ROM | disk | FTP | other *** search
- Path: news.uni-jena.de!news
- From: mkt@isun04.inf.uni-jena.de (Tilo Koerbs)
- Newsgroups: comp.lang.c++
- Subject: Re: novice question on copy constru
- Date: 31 Jan 1996 13:13:36 GMT
- Organization: Lehrstuhl fuer Rechnerarchitektur- und kommunikation, FSU Jena
- Message-ID: <4enpu0$qlr@fsuj01.rz.uni-jena.de>
- References: <4efpie$jsq@news.ust.hk>
- Reply-To: mkt@isun04.inf.uni-jena.de
- NNTP-Posting-Host: isun07.inf.uni-jena.de
-
- >To the question:
- >>I don't understand why one should create a copy constructor. Doesn't the
- >>computer will do the job for you when pass arguments by value? Thanks
-
- You don't need to write a copy constructor. It is always created
- by the compiler. (In contrast to the default constructor,
- which is only created if no constructor is written by the user.)
-
- The only problem is: If your class contains pointers (better:
- dynamically allocated data). In this case You need to write
- the constructor. The compiler generates only bitwise copies. And this
- is not what You want for pointers. They will point to the data
- belonging to the object You copy from.
-
- Again: If You don't have pointers in your class You probably never need to
- write a copy constructor by hand.
-
-
-